package com.example.demo_2;

import org.apache.ibatis.annotations.*;

//@Repository
//public class StuDao {
//    @Autowired
//    JdbcTemplate jdbcTemplate;
//
//    public Stu getUserByName(String Name) {
//        String sql = "select * from mess where name = ?";
//        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Stu.class), Name);
//    }
//}
//添加Mapper注解，让UserDao接口，成为Mybatis映射器接口
//@Mapper
//public interface StuDao {
//    @Select("select * from user where username = #{username}")
//    Stu getUserByName(String username);
//}
@Mapper
public interface StuDao {
    @Results(id = "userMap",value = {
            @Result(property = "username",column = "username"),
            @Result(property = "age",column = "age"),
            @Result(property = "password",column = "password")
    })
    @Select("select * from user where username = #{username} and password = #{password}")
    Stu getUserByName(@Param("username") String username);

    @Insert("insert into user(username,password,age) values (#{username},#{password},#{age})")
    int creatUser(Stu stu);
}